package net.projecteuler.programs.program0006;

import net.projecteuler.programs.TimeLogger;

/**
 * Sum square difference
 *
 * The sum of the squares of the first ten natural numbers is,
 *
 * 12 + 22 + ... + 102 = 385
 * The square of the sum of the first ten natural numbers is,
 *
 * (1 + 2 + ... + 10)2 = 552 = 3025
 *  Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 ? 385 = 2640.
 *
 *  Find the difference between the sum of the squares of the first one hundred natural numbers and the square of the sum.
 *
 * Created by zhaojjd on 2016/3/21.
 */
public class Program0006 {

    public long calculate(int num){
        int sum = (1 + num)*num/2;
        long rst = sum * sum;
        for(int i = num; i > 0; i--){
            rst -= i * i;
        }
        return rst;
    }

    public static void main(String[] args) {
        Program0006 p = new Program0006();

        TimeLogger.tag();
        System.out.println("p.calculate(100) = " + p.calculate(100));
        
        TimeLogger.print();
    }

}
